
const UserService = require('../service/user')

//增
const addUserController = async(ctx,next)=>{
    let result = await UserService.addUserService()
    console.log(result,'result1');
    if(result){
        ctx.body={
            code:200,
            msg:'add,success',
            data:result
        }
    }else {
        ctx.body={
            code:403,
            msg:'add,err',
            data:result
        }
    }
}
//查
const getUserController = async(ctx,next)=>{
    let result = await UserService.getUserService()
    console.log(result,'result2');
    if(result){
        ctx.body={
            code:200,
            msg:'get,success',
            data:result
        }
    }else {
        ctx.body={
            code:403,
            msg:'get,err',
            data:result
        }
    }
}
//删
const delUserController = async(ctx,next)=>{
    let result = await UserService.delUserService()
    console.log(result,'result3');
    if(result){
        ctx.body={
            code:200,
            msg:'del,success',
            data:result
        }
    }else {
        ctx.body={
            code:403,
            msg:'del,err',
            data:result
        }
    }
}

//修改
const updataUserController = async(ctx,next)=>{
    console.log(ctx.request.body)
    //查看
    let result = await addService.updataUserService()
    console.log(result,'result0')
     if(result){
         ctx.body={
             code:200,
             mag:'updataUserController,success',
             data:result
         }
     }else {
         ctx.body={
             code:403,
             mag:'params'
         }
     }
 }



//获取
const getListController = async(ctx,next)=>{
    let result = await UserService.getList()
    console.log( result );
    ctx.body = {
        code:200,
        msg:'get success'
    }
}

//增加
const addListController = async(ctx,next)=>{
    console.log(222222);
    console.log(ctx.request.body)
    let result = await UserService.addList(ctx.request.body)
    console.log(result)
    if(result){
        ctx.body={
            code:200,
            msg:'add success',
            data:null
        }
    }else {
        ctx.body={
            code:403,
            msg:'add err',
            data:null
        }
    }
}

//删除
const delListController = async(ctx,next)=>{
    console.log(ctx.request.body)
    let result = await UserService.delList(ctx.request.body)
    console.log(result)
    if(result){
        ctx.body={
            code:200,
            msg:'del success',
            data:null
        }
    }else {
        ctx.body={
            code:403,
            msg:'del err',
            data:null
        }
    }
}

//修改
const updataListController = async(ctx,next)=>{
    console.log(ctx.request.query)
    let result = await UserService.updataList(ctx.request.query)
    console.log(result)
    if(result){
        ctx.body={
            code:200,
            msg:'updata success',
            data:null
        }
    }else {
        ctx.body={
            code:403,
            msg:'updata err',
            data:null
        }
    }
}

module.exports = {
    getListController,
    addListController,
    delListController,
    updataListController,
    addUserController,
    getUserController,
    delUserController,
    updataUserController

}